package com.probox.common.entity.domain.order;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.probox.common.core.annotation.Excel;
import com.probox.common.core.enums.*;
import com.probox.common.core.utils.money.MoneyUtils;
import com.probox.common.core.utils.money.PriceFormatUtil;
import com.probox.order.api.domain.OrderItemVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单子对象 order_info
 *
 * @author usoft
 * @date 2021-05-27
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("order_info")
@ApiModel(description = "订单子对象")
public class OrderInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 订单ID
     */
    //默认主键自增
    @TableId(value = "ORDER_UID", type = IdType.AUTO)
    private Long orderUid;

    private String orderTitle;

    /**
     * 平台ID
     */
    //@Excel(name = "平台ID")
    @ApiModelProperty(value = "平台ID(平台ID)")
    private Long platformUid;

    /**
     * 供应商ID
     */
    //@Excel(name = "供应商ID")
    @ApiModelProperty(value = "供应商ID(供应商ID)")
    private Long supplierUid;

    /**
     * 供应商名称
     */
    //@Excel(name = "供应商名称")
    @ApiModelProperty(value = "供应商名称(供应商名称)")
    private String supplierName;

    /**
     * 订单类型 good商品/gift赠品/lottery奖品
     */
    @Excel(name = "订单类型 ")
    @ApiModelProperty(value = "订单类型 good商品/gift赠品/lottery奖品 ")
    private String orderType;

    /**
     * 商家订单号
     */
    @Excel(name = "订单号")
    @ApiModelProperty(value = "商家订单号(商家订单号)")
    private String orderNo;

    /**
     * 支付订单号
     */
    //@Excel(name = "支付订单号")
    @ApiModelProperty(value = "支付订单号(支付订单号)")
    private String parentOrderNo;

    /**
     * 客户ID
     */
    @Excel(name = "客户ID")
    @ApiModelProperty(value = "客户ID(客户ID)")
    private Long customerUid;

    /**
     * 客户名称
     */
    @Excel(name = "客户名称")
    @ApiModelProperty(value = "客户名称(客户名称)")
    private String customerName;

    /**
     * 手机号码
     */
    @Excel(name = "手机号码")
    @ApiModelProperty(value = "手机号码(手机号码)")
    private String phone;

    /**
     * 订单状态 1:有效 0:用户未支付取消 -1:过期未支付无效 -2:用户已支付取消
     */
    @Excel(name = "订单状态")
    @ApiModelProperty(value = "订单状态 1:有效 0:用户未支付取消 -1:过期未支付无效 -2:用户已支付取消 ")
    private String orderStatus;

    /**
     * 支付状态 0 未支付/1已支付
     */
    @Excel(name = "支付状态 0 未支付/1已支付")
    @ApiModelProperty(value = "支付状态 0 未支付/1已支付 ")
    private String payStatus;

    /**
     * 支付方式 wechat(微信)/balance(余额)/alipay(支付宝)/netbank(网银)
     */
    @Excel(name = "支付方式")
    @ApiModelProperty(value = "支付方式 wechat(微信)/balance(余额)/alipay(支付宝)/netbank(网银) ")
    private String payMethod;

    @TableField(exist = false)
    private List<String> payMethodList;

    /**
     * 订单来源(wechat小程序/H5/Web/Android/IOS)
     */
    @Excel(name = "订单来源")
    @ApiModelProperty(value = "订单来源(wechat小程序/H5/Web/Android/IOS) ")
    private String platSource;

    /**
     * 商品金额，不含运费
     */
    @Excel(name = "商品金额")
    @ApiModelProperty(value = "商品金额，不含运费(商品金额，不含运费)")
    private Long orderAmount;

    /**
     * 支付金额(已经减去代金券、减去余额、减去折扣金额)
     */
    @Excel(name = "支付金额")
    @ApiModelProperty(value = "支付金额(已经减去代金券、减去余额、减去折扣金额) ")
    private Long payAmount;

    /**
     * 运费
     */
    @Excel(name = "运费")
    @ApiModelProperty(value = "运费(运费)")
    private Long freightAmount;

    /**
     * 折扣 1 代表百分之一折扣
     */
    @Excel(name = "折扣 ")
    @ApiModelProperty(value = "折扣 1 代表百分之一折扣 ")
    private Long discountRate;

    /**
     * 折扣金额
     */
    @Excel(name = "折扣金额")
    @ApiModelProperty(value = "折扣金额(折扣金额)")
    private Long discountAmount;

    /**
     * 使用代金券支付(废弃，使用父订单的代金券字段)
     */
    //@Excel(name = "使用代金券支付(废弃，使用父订单的代金券字段)")
    @ApiModelProperty(value = "使用代金券支付(废弃，使用父订单的代金券字段) ")
    private Long useCouponUid;

    /**
     * 使用代金券金额
     */
    @Excel(name = "优惠券金额")
    @ApiModelProperty(value = "使用代金券金额(使用代金券金额)")
    private Long useCouponAmount;

    /**
     * 余额支付
     */
    @Excel(name = "金币支付")
    @ApiModelProperty(value = "余额支付(余额支付)")
    private Long payByBalance;

    /**
     * 积分抵扣
     */
    @Excel(name = "菠萝花")
    @ApiModelProperty(value = "积分抵扣(积分抵扣)")
    private Long payByScore;

    /**
     * 红包支付
     */
    @Excel(name = "银币支付")
    @ApiModelProperty(value = "红包支付(红包支付)")
    private Long payByRedBag;

    /**
     * 货币单位
     */
    @Excel(name = "货币单位")
    @ApiModelProperty(value = "货币单位(货币单位)")
    private String currencyUnit;

    /**
     * 支付时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "支付时间(支付时间)")
    private Date payTime;

    /**
     * 下单时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "下单时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "下单时间(下单时间)")
    private Date createTime;

    /**
     * 订单取消时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    //@Excel(name = "订单取消时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "订单取消时间(订单取消时间)")
    private Date cancelTime;

    /**
     * 买家留言
     */
    @Excel(name = "买家留言")
    @ApiModelProperty(value = "买家留言(买家留言)")
    private String buyMes;

    /**
     * 未支付订单过期时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    //@Excel(name = "未支付订单过期时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "未支付订单过期时间(未支付订单过期时间)")
    private Date expireDate;

    /**
     * 备注
     */
    @Excel(name = "备注")
    @ApiModelProperty(value = "备注(备注)")
    private String remark;

    /**
     * ip地址
     */
    //@Excel(name = "ip地址")
    @ApiModelProperty(value = "ip地址(ip地址)")
    private String ip;

    /**
     * 开票信息，为空不需要开票
     */
    //@Excel(name = "开票信息，为空不需要开票")
    @ApiModelProperty(value = "开票信息，为空不需要开票(开票信息，为空不需要开票)")
    private Long invoiceUid;

    /**
     * 开票状态 0未开票1已开票
     */
    //@Excel(name = "开票状态 0未开票1已开票")
    @ApiModelProperty(value = "开票状态 0未开票1已开票(开票状态 0未开票1已开票)")
    private String invoiceStatus;

    /**
     * 配送方式 express快递、ziti自提、logistics物流
     */
    //@Excel(name = "配送方式 express快递、ziti自提、logistics物流")
    @ApiModelProperty(value = "配送方式 express快递、ziti自提、logistics物流 ")
    private String deliverMethod;

    /**
     * 收货地址ID
     */
    //@Excel(name = "收货地址ID")
    @ApiModelProperty(value = "收货地址ID(收货地址ID)")
    private Long addressUid;

    /**
     * 发货时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "发货时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "发货时间(发货时间)")
    private Date sendTime;

    /**
     * 发货状态 -1取消发货0 未发货/1已发货/2已收货
     */
    @Excel(name = "发货状态 -1取消发货0 未发货/1已发货/2已收货")
    @ApiModelProperty(value = "发货状态 -1取消发货0 未发货/1已发货/2已收货 ")
    private String sendStatus;

    /**
     * 包裹状态 0待揽收/1运输中/2已妥投
     */
    //@Excel(name = "包裹状态 0待揽收/1运输中/2已妥投")
    @ApiModelProperty(value = "包裹状态 0待揽收/1运输中/2已妥投 ")
    private String orderPackStatus;

    /**
     * 签收时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    //@Excel(name = "签收时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "签收时间(签收时间)")
    private Date signTime;

    /**
     * 收货时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "收货时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "收货时间(收货时间)")
    private Date receiveTime;

    /**
     * 自动收货时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    //@Excel(name = "自动收货时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "自动收货时间(自动收货时间)")
    private Date autoReceiveTime;

    /**
     * 评价状态  0待评价 1已评价
     */
    @Excel(name = "评价状态  0待评价 1已评价")
    @ApiModelProperty(value = "评价状态  0待评价 1已评价(评价状态  0待评价 1已评价)")
    private String commentStatus;

    /**
     * 评价时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "评价时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "评价时间(评价时间)")
    private Date commentTime;

    /**
     * 修改人
     */
    //@Excel(name = "修改人")
    @ApiModelProperty(value = "修改人(修改人)")
    private Long updateUser;

    /**
     * 修改人账号名称
     */
    //@Excel(name = "修改人账号名称")
    @ApiModelProperty(value = "修改人账号名称(修改人账号名称)")
    private String updateUserName;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    //@Excel(name = "修改时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "修改时间(修改时间)")
    private Date updateTime;

    @ApiModelProperty(value = "活动参与ID")
    private Long joinUid;

    /**
     * 是否需要分账 (Y-是，需要分账;N-否，不分账)
     */
    @ApiModelProperty(value = "是否需要分账 (Y-是，需要分账;N-否，不分账)")
    private String profitSharing;

    /**
     * 分账状态(0未发起分账/1已发起分账/2已解冻分润)
     */
    @ApiModelProperty(value = "分账状态(0未发起分账/1已发起分账/2已解冻分润)")
    private String isShared;

    private String createName;

    private String collectionName;

    private Long createUid;

    /**
     * 人工出价格
     */
    private Long renGongMoney;

    /**
     * 状态，处理前端订单查询
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "查询状态（all全部/unpay待支付/unsend待发货/unreceive待收货/uncomment待评价）")
    private String queryStatus;

    //快递公司主键ID
    @TableField(exist = false)
    private Long kdUid;
    //快递单号
    @TableField(exist = false)
    private String expressNo;
    //发货类型
    @TableField(exist = false)
    private String deliverType;

    //子订单
    @TableField(exist = false)
    private List<OrderInfoItem> orderInfoItemList;

    @TableField(exist = false)
    private List<OrderItemVo> itemList;

    @TableField(exist = false)
    private List<String> payTimeArray;
    @TableField(exist = false)
    private List<String> createTimeArray;
    @TableField(exist = false)
    private List<String> sendTimeArray;
    @TableField(exist = false)
    private List<String> signTimeArray;
    @TableField(exist = false)
    private List<String> receiveTimeArray;
    @TableField(exist = false)
    private List<String> commentTimeArray;


    @ApiModelProperty(value = "订单整体状态(unpay待支付/unsend待发货/unreceive待收货/uncomment待评价/completed已完成)")
    public String getStatus() {
        String rst = OrderQueryStatusEnum.completed.getKey();
        if (PayStatusEnum.unpaid.getKey().equals(payStatus)) {
            rst = OrderQueryStatusEnum.unpay.getKey();
        } else if (SendStatusEnum.unShip.getKey().equals(sendStatus)) {
            rst = OrderQueryStatusEnum.unsend.getKey();
        } else if (SendStatusEnum.ship.getKey().equals(sendStatus)) {
            rst = OrderQueryStatusEnum.unreceive.getKey();
        } else if (CommentStatusEnum.unComment.getKey().equals(commentStatus)) {
            rst = OrderQueryStatusEnum.uncomment.getKey();
        }
        return rst;
    }

    //订单整体状态
    @ApiModelProperty(value = "订单整体状态描述")
    public String getStatusName() {
        String rst = OrderQueryStatusEnum.completed.getValue();
        if (PayStatusEnum.unpaid.getKey().equals(payStatus)) {
            rst = OrderQueryStatusEnum.unpay.getValue();
        } else if (SendStatusEnum.unShip.getKey().equals(sendStatus)) {
            rst = OrderQueryStatusEnum.unsend.getValue();
        } else if (SendStatusEnum.ship.getKey().equals(sendStatus)) {
            rst = OrderQueryStatusEnum.unreceive.getValue();
        } else if (CommentStatusEnum.unComment.getKey().equals(commentStatus)) {
            rst = OrderQueryStatusEnum.uncomment.getValue();
        }
        return rst;
    }

    public String getOrderAmountStr() {
        return PriceFormatUtil.format(orderAmount);
    }

    public String getPayAmountStr() {
        return PriceFormatUtil.format(payAmount);
    }

    public String getDiscountAmountStr() {
        return PriceFormatUtil.format(discountAmount);
    }

    public String getReGongMoneyStr() {
        return PriceFormatUtil.format(renGongMoney);
    }

    public String getUseCouponAmountStr() {
        return PriceFormatUtil.format(useCouponAmount);
    }

    public String getPayByBalanceStr() {
        return PriceFormatUtil.format(payByBalance);
    }

    public String getFreightAmountStr() {
        return PriceFormatUtil.format(freightAmount);
    }

    public String getOrderTypeName() {
        return OrderTypeEnum.getNameByKey(orderType);
    }

    public String getOrderStatusName() {
        return OrderStatusEnum.getNameByKey(orderStatus);
    }

    public String getPayStatusName() {
        return PayStatusEnum.getNameByKey(payStatus);
    }

    public String getPayMethodName() {
        return PayMethodEnum.getNameByKey(payMethod);
    }

    public String getPlatSourceName() {
        return PlatSourceEnum.getNameByKey(platSource);
    }

    public String getInvoiceStatusName() {
        if (ObjectUtil.isNull(invoiceUid))
            return "无需开票";
        return InvoiceStatusEnum.getNameByKey(invoiceStatus);
    }

    public String getDeliverMethodName() {
        return DeliverMethodEnum.getNameByKey(deliverMethod);
    }

    public String getSendStatusName() {
        return SendStatusEnum.getNameByKey(sendStatus);
    }

    public String getPackStatusName() {
        return PackStatusEnum.getNameByKey(orderPackStatus);
    }

    public String getCommentName() {
        return CommentStatusEnum.getNameByKey(commentStatus);
    }

    public String getPayByRedBagStr(){
        return MoneyUtils.changeF2Y(payByRedBag);
    }

    private Long storeId;
    /**
     * 是否为叠叠乐
     */
    private String isDdl;

    @TableField(exist = false)
    private String storeName;


    @TableField(exist = false)
    private String proName;

    @TableField(exist = false)
    private String proNo;

    //折扣订单标志
    @TableField(exist = false)
    private String discount;

    //多门店ID
    @TableField(exist = false)
    private List<Long> storeIds;

    //门店分组
    @TableField(exist = false)
    private Long storeGroupId;

    @TableField(exist = false)
    private BigDecimal amount;
}
